using Game.Const;
using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;
using UnityEngine;

namespace Game.Component
{
	public class ATMItem : BaseItem
	{
		public enum State
		{
			Full = 0,
			Empty = 1
		}

		private State state;

		private Sprite fullSprite;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			CheckState();
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			if (base.itemData.createIds != null && archiveData.createIndexs.Count < base.itemData.createAmount)
			{
				Transform transform = model.Find("CreatePoint");
				BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(base.itemData.createIds[Random.Range(0, base.itemData.createIds.Length)], transform.position, 0);
				if (baseItem != null)
				{
					AddCreateItem(baseItem);
					baseItem.DropDown(base.transform.position);
					CheckState();
					Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", baseItem.transform.position + new Vector3(0f, 0.4f, -0.0004f), 2f);
				}
				Singleton<AudioManager>.Instance.PlaySound("sound_atm");
			}
			else
			{
				Singleton<AudioManager>.Instance.PlaySound("sound_atm_error");
			}
		}

		private void CheckState()
		{
			if (archiveData.createIndexs.Count < base.itemData.createAmount)
			{
				if (state == State.Empty)
				{
					model.Find("Empty").gameObject.SetActive(false);
					state = State.Full;
				}
			}
			else if (state == State.Full)
			{
				model.Find("Empty").gameObject.SetActive(true);
				state = State.Empty;
			}
		}

		public override void RemoveCreateItem(BaseItem item)
		{
			base.RemoveCreateItem(item);
			CheckState();
		}
	}
}
